home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995 February: Tool Chest / Dev.CD Feb 95 / Dev.CD Feb 95.toast / Tool Chest / QuickDraw GX / QuickDraw GX Info / QuickDraw GX Interfaces / Interfaces & Libraries / interfaces / math routines.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-30  |  5.4 KB  |  116 lines  |  [TEXT/MPS ]

  1. /* graphics:
  2.     math routines
  3.     by Cary Clark, Georgiann Delaney, Herb Derby, Michael Fairman, Pablo Fernicola, Dave Good, Josh Horwich, Barton House, Robert Johnson, Keith McGreggor, Mike Reed, Oliver Steele, David Van Brink, Chris Yerga
  4.     Copyright 1987 - 1994 Apple Computer, Inc.  All rights reserved.    */
  5.  
  6. #pragma once
  7.  
  8. #ifndef mathRoutinesIncludes
  9.     #define mathRoutinesIncludes
  10.  
  11.     #ifdef __powerc
  12.         #ifndef __FIXMATH__
  13.             #ifdef fixed1
  14.                 #undef fixed1
  15.                 #undef fract1
  16.             #endif
  17.             #include <FixMath.h>
  18.         #endif
  19.     #endif
  20.  
  21.     #ifndef mathTypesIncludes
  22.         #include "math types.h"
  23.     #endif
  24.  
  25.     #ifndef graphicsLinkageIncludes
  26.         #include "graphics linkage.h"
  27.     #endif
  28.  
  29.     #ifdef __cplusplus
  30.     extern "C" {
  31.     #endif
  32.  
  33.     gxMapping *CopyToMapping(gxMapping *target, const gxMapping *source) GXInlineCode(0x31, gxNeedClient);
  34.     gxMapping *InvertMapping(gxMapping *target, const gxMapping *source) GXInlineCode(0x32, gxNeedClient);
  35.     gxMapping *MapMapping(gxMapping *target, const gxMapping *source) GXInlineCode(0x33, gxNeedClient);
  36.     gxMapping *MoveMapping(gxMapping *target, Fixed hOffset, Fixed vOffset) GXInlineCode(0x34, gxNeedClient);
  37.     gxMapping *MoveMappingTo(gxMapping *target, Fixed hPosition, Fixed vPosition) GXInlineCode(0x35, gxNeedClient);
  38.     gxMapping *NormalizeMapping(gxMapping *target) GXInlineCode(0x36, gxNeedClient);
  39.     gxMapping *RotateMapping(gxMapping *target, Fixed angle, Fixed xCenter, Fixed yCenter) GXInlineCode(0x37, gxNeedClient);
  40.     gxMapping *ScaleMapping(gxMapping *target, Fixed hFactor, Fixed vFactor, Fixed xCenter, Fixed yCenter) GXInlineCode(0x38, gxNeedClient);
  41.     gxMapping *ResetMapping(gxMapping *target) GXInlineCode(0x39, gxNeedClient);
  42.     gxMapping *SkewMapping(gxMapping *target, Fixed skewX, Fixed skewY, Fixed xCenter, Fixed yCenter) GXInlineCode(0x3a, gxNeedClient);
  43.  
  44.     void MapPoints(const gxMapping *source, long count, gxPoint vector[]) GXInlineCode(0x3b, gxNeedClient);
  45.  
  46.     short FirstBit(unsigned long) GXInlineCode(0x3c, gxNeedClient);
  47.     short WideScale(const wide *source) GXInlineCode(0x3d, gxNeedClient);
  48.  
  49.     short LinearRoot(Fixed first, Fixed last, fract t[]) GXInlineCode(0x3e, gxNeedClient);
  50.     short QuadraticRoot(Fixed first, Fixed control, Fixed last, fract t[]) GXInlineCode(0x3f, gxNeedClient);
  51.  
  52.     gxPoint *PolarToPoint(const gxPolar *, gxPoint *) GXInlineCode(0x40, gxNeedClient);
  53.     gxPolar *PointToPolar(const gxPoint *, gxPolar *) GXInlineCode(0x41, gxNeedClient);
  54.  
  55.     fract FractCubeRoot(fract source) GXInlineCode(0x42, gxNeedClient);
  56.     fract FractDivide(fract dividend, fract divisor) GXInlineCode(0x43, gxNeedClient);
  57.     fract FractMultiply(fract multiplicand, fract multiplier) GXInlineCode(0x44, gxNeedClient);
  58.     fract FractSineCosine(Fixed degrees, fract *cosine) GXInlineCode(0x45, gxNeedClient);
  59.     fract FractSquareRoot(fract source) GXInlineCode(0x46, gxNeedClient);
  60.  
  61.     Fixed FixedDivide(Fixed dividend, Fixed divisor) GXInlineCode(0x47, gxNeedClient);
  62.     Fixed FixedMultiply(Fixed multiplicand, Fixed multiplier) GXInlineCode(0x48, gxNeedClient);
  63.  
  64.     /* This next call is (source * multiplier / divisor) -- it avoids underflow, overflow by using wides */
  65.     long MultiplyDivide(long source, long multiplier, long divisor) GXInlineCode(0x49, gxNeedClient);
  66.  
  67.     unsigned long Magnitude(long deltaX, long deltaY) GXInlineCode(0x4a, gxNeedClient);
  68.     long VectorMultiplyDivide(long count, const long *vector1, long step1, const long *vector2, long step2, long divisor) GXInlineCode(0x4b, gxNeedClient);
  69. #ifndef __powerc
  70.     wide *WideAdd(wide *target, const wide *source) GXInlineCode(0x4c, gxNeedClient);
  71.     short WideCompare(const wide *target, const wide *source) GXInlineCode(0x4d, gxNeedClient);
  72.     wide *WideNegate(wide *target) GXInlineCode(0x4e, gxNeedClient);
  73.     wide *WideShift(wide *target, long shift) GXInlineCode(0x4f, gxNeedClient);
  74.     unsigned long WideSquareRoot(const wide *source) GXInlineCode(0x50, gxNeedClient);
  75.     wide *WideSubtract(wide *target, const wide *source) GXInlineCode(0x51, gxNeedClient);
  76.  
  77.     wide *WideMultiply(long multiplicand, long multiplier, wide *target) GXInlineCode(0x52, gxNeedClient);
  78.     long WideDivide(const wide *dividend, long divisor, long *remainder) GXInlineCode(0x53, gxNeedClient);        /* returns the quotient */
  79. #endif
  80.     wide *VectorMultiply(long count, const long *vector1, long step1, const long *vector2, long step2, wide *dot) GXInlineCode(0x54, gxNeedClient);
  81. #ifndef __powerc
  82.     wide *WideWideDivide(wide *dividend, long divisor, long *remainder) GXInlineCode(0x55, gxNeedClient);    /* quotient replaces dividend */
  83. #endif
  84.  
  85.     unsigned long RandomBits(long count, long focus) GXInlineCode(0x56, gxNeedClient);
  86.     void SetRandomSeed(const wide *seed) GXInlineCode(0x57, gxNeedClient);
  87.     wide *GetRandomSeed(wide *seed) GXInlineCode(0x58, gxNeedClient);
  88.  
  89.     #ifdef __cplusplus
  90.     }
  91.     #endif
  92.  
  93.     #define FixedRound(a)        ((short)((Fixed)(a) + fixed1/2 >> 16))
  94.     #define FixedSquareRoot(a)    ((Fixed)FractSquareRoot(a) + 64 >> 7)
  95.     #define FixedTruncate(a)        ((short)((Fixed)(a) >> 16))
  96.  
  97.     #define FixedToFract(a)        ((fract)(a) << 14)
  98.     #define FractToFixed(a)        ((Fixed)(a) + 8192L >> 14)
  99.  
  100.     #define FixedToInt(a)       ((short)((Fixed)(a) + fixed1/2 >> 16))
  101.     #define IntToFixed(a)       ((Fixed)(a) << 16)
  102.  
  103.     #define FixedToFloat(a)     ((float)(a) / fixed1)
  104.     #define FloatToFixed(a)         ((Fixed)((float)(a) * fixed1))
  105.  
  106.     #define FractToFloat(a)     ((float)(a) / fract1)
  107.     #define FloatToFract(a)     ((fract)((float)(a) * fract1))
  108.  
  109.     #define ColorToFract(a)     (((fract) (a) << 14) + ((fract)(a) + 2 >> 2))
  110.     #define FractToColor(a)     ((gxColorValue) ((a) - ((a) >> 16) + 8191 >> 14))
  111.  
  112.     #define ff(a)               IntToFixed(a)
  113.     #define fl(a)               FloatToFixed(a)
  114.  
  115. #endif
  116.